package pl.ydp.components.mathcell.mathcell
{
	import flash.events.TimerEvent;
	import flash.geom.Point;
	
	import mx.controls.TextArea;
	import flash.events.FocusEvent;
	import mx.managers.IFocusManagerComponent;
	
	/**
	 * This is the class for the extended version of cell.
	 * This version can be used for debugging, presenting the
	 * mathcell functionality or other purposes.
	 */
	public class CellExtended extends Cell implements IFocusManagerComponent
	{
		public function CellExtended()
		{
			super();
			
			direction = "horizontal";
			result = new TextArea;
			result.name = "result";
			result.editable = false;
			result.width = WIDTH;
			result.height = HEIGHT;
			result.setStyle("textAlign", "center");
			result.setStyle("fontSize", HEIGHT*0.8);
			result.setStyle("paddingTop", 0);
			
			//text.x = 128;
			
			//text.visible = false;
			result.setStyle("borderThickness",4);
			result.setStyle("borderColor",0x000000);
			result.setStyle("borderStyle","solid");
			result.setStyle("backgroundColor",0xdfdfdf);
			
			percentWidth = 200;
			
			addChild(result);
		}
		
		private var result:TextArea;
		public var drawResult:Boolean = true;
		
		override protected function cellStateChanged():void{
			super.cellStateChanged();
		}
		
		override public function styleChanged(styleProp:String):void{
			super.styleChanged(styleProp);
			if (direction == "horizontal"){
				width = 256 + getStyle("gap");
			} else {
				height = 256 + getStyle("gap");
			}
		}
		
		override public function inputLockedCharacter(charCode:Number):Boolean{
			return super.inputLockedCharacter(charCode);
			//return false;
		}
		
		override protected function onApproveTimer(e:TimerEvent):void{
			if (drawResult)
				super.onApproveTimer(e);
			else {
				approveTimer.stop();
				process();
			}
		}
		
		public function forceDraw():void{
			for each (var stroke:Array in penPoints){
				if (stroke.length == 0)
					continue;
				canvas.startDrawing(stroke[0].x, stroke[0].y);
				for each (var point:Point in stroke){
					canvas.processDrawing(point.x, point.y);
				}
				canvas.stopDrawing(stroke[stroke.length-1].x, stroke[stroke.length-1].y);
			}
			
		}
		
		
		override public function process():void{
			super.process();
		}
		
		public function getExpressionContent():String{
			if (expressionManager.expressionContent.length > 0){
				return expressionManager.expressionContent;
			}
			return "";	
		}
		
		public function setPenPoints(pp:Array):void{
			penPoints = pp;
		}
		
		override protected function focusInHandler(event:FocusEvent):void{
			hasFocus = true;
		} 
		
		override protected function focusOutHandler(event:FocusEvent):void{
			hasFocus = false;
		} 
	}
}